<%
local dsp = require "luci.dispatcher"
-%>

<p id="_status"></p>

<script type="text/javascript">//<![CDATA[
	XHR.poll(3,'<%=dsp.build_url("admin/services/passwall/status")%>', null,
		function(x, json) {
			if (x && x.status == 200) {
				var _status = document.getElementById('_status');
				if (_status) {
					if (json.haproxy_status) {
						_status.innerHTML = '<input type="button" class="cbi-button cbi-input-apply" value="<%:Enter interface%>" onclick="openwebui()" />';
					}
				}
			}
		});
		
	function openwebui(){
		var url = window.location.host+":<%=luci.sys.exec("uci -q get passwall.@global_haproxy[0].console_port"):gsub("^%s*(.-)%s*$", "%1")%>";
		window.open('http://'+url,'target','');
	}
//]]></script>
